package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PhysicalStudent;
import com.ruoyi.system.service.IPhysicalStudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import java.io.IOException;

/**
 * 警校考生体能测评信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/system/physical")
public class PhysicalStudentController extends BaseController
{
    @Autowired
    private IPhysicalStudentService physicalStudentService;

    /**
     * 查询警校考生体能测评信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:physical:list')")
    @GetMapping("/list")
    public TableDataInfo list(PhysicalStudent physicalStudent)
    {
        startPage();
        List<PhysicalStudent> list = physicalStudentService.selectPhysicalStudentList(physicalStudent);
        return getDataTable(list);
    }

    /**
     * 导出警校考生体能测评信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:physical:export')")
    @Log(title = "警校考生体能测评信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PhysicalStudent physicalStudent)
    {
        List<PhysicalStudent> list = physicalStudentService.selectPhysicalStudentList(physicalStudent);
        ExcelUtil<PhysicalStudent> util = new ExcelUtil<PhysicalStudent>(PhysicalStudent.class);
        util.exportExcel(response, list, "警校考生体能测评信息数据");
    }
    
    /**
     * 导入警校考生体能测评信息
     */
    @PreAuthorize("@ss.hasPermi('system:physical:import')")
    @Log(title = "警校考生体能测评信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<PhysicalStudent> util = new ExcelUtil<PhysicalStudent>(PhysicalStudent.class);
        List<PhysicalStudent> physicalStudentList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = physicalStudentService.importPhysicalStudent(physicalStudentList, updateSupport, operName);
        return success(message);
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<PhysicalStudent> util = new ExcelUtil<PhysicalStudent>(PhysicalStudent.class);
        util.importTemplateExcel(response, "警校考生体能测评信息");
    }

    /**
     * 获取警校考生体能测评信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:physical:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(physicalStudentService.selectPhysicalStudentById(id));
    }

    /**
     * 新增警校考生体能测评信息
     */
    @PreAuthorize("@ss.hasPermi('system:physical:add')")
    @Log(title = "警校考生体能测评信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PhysicalStudent physicalStudent)
    {
        return toAjax(physicalStudentService.insertPhysicalStudent(physicalStudent));
    }

    /**
     * 修改警校考生体能测评信息
     */
    @PreAuthorize("@ss.hasPermi('system:physical:edit')")
    @Log(title = "警校考生体能测评信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PhysicalStudent physicalStudent)
    {
        return toAjax(physicalStudentService.updatePhysicalStudent(physicalStudent));
    }

    /**
     * 批量修改警校考生体能测评结果
     */
    @PreAuthorize("@ss.hasPermi('system:physical:edit')")
    @Log(title = "警校考生体能测评信息", businessType = BusinessType.UPDATE)
    @PutMapping("/batchPass")
    public AjaxResult batchUpdateQualificationReview(@RequestBody List<PhysicalStudent> physicalStudentList)
    {
        return toAjax(physicalStudentService.batchUpdateQualificationReview(physicalStudentList));
    }

    /**
     * 删除警校考生体能测评信息
     */
    @PreAuthorize("@ss.hasPermi('system:physical:remove')")
    @Log(title = "警校考生体能测评信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(physicalStudentService.deletePhysicalStudentByIds(ids));
    }
}
